package chapter_13_proxy.static_proxy;

/**
 * Created by CharloYao on 2017/10/11.
 * 静态代理类，实现了代理接口
 */
public class ProxySubject implements Subject {

    //代理类持有一个委托类的实例引用
    private Subject delegate;

    public ProxySubject(Subject delegate) {
        this.delegate = delegate;
    }

    /**
     * 将请求分派给委托类执行，记录任务前后时间
     *
     * @param taskName
     */
    @Override
    public void dealTask(String taskName) {
        long stime = System.currentTimeMillis();
        delegate.dealTask(taskName);
        long etime = System.currentTimeMillis();

        System.out.println("任务耗时：" + (etime - stime) + "毫秒");
    }
}
